In many current computing systems, events are used to communicate happenings of interest between objects. For instance, events enable a class or object to notify other classes or other objects when something of interest occurs. The class that sends (or raises) the event is known as the publisher and the classes that receive (or handle) the event are known as subscribers or event handlers.
By way of example, an object may subscribe to events raised by controls on a user interface, such as buttons, list boxes, or other types of controls. The publisher (the object representing the control) determines when the event is raised and subscribers determine the action to be taken in response to the event.
Programmers often write custom code that is called when a given event is raised. For instance, code may take an action that the programmer wants to perform when a user clicks on a certain button in a given context.
In many conventional computing languages such as C# and Java, event subscription is dynamic. This means that in order to subscribe to an event, the subscriber requires an instance of the class raising the event (an instance of the publisher). By way of example, in one language, in order to subscribe to an event, the addition assignment operator (+=) is used to attach an event handler to an event.
Assume, for instance, that an object named Publisher has an event RaiseCustomEvent. The following code in Table 1 is in the language C#. The BankAccount class raises an event whenever a withdrawal occurs. The TextOnWithdrawal class is subscribing to the event. For instance, the subscriber will send a text message to the account owner whenever any withdrawal occurs. The Program class uses the BankAccount class and initiates a withdrawal:
TABLE 1public class BankAccount{ public delegate void WithDrawalDelegate(decimal amount); public event WithDrawalDelegate onWithDrawal; public void WithDraw(decimal amount) {  //Raise the event  onWithDrawal(amount);  // ... }}public class TextingOnWithDrawal{ public static void onWithDrawal(decimal amount) {  // Send text message }}class Program{ static void Main(string[ ] args) {  BankAccount bankAccount = new BankAccount( );   bankAccount.onWithDrawal +=   TextingOnWithDrawal.onWithDrawal;  bankAccount.WithDraw(500); }}
In the example in Table 1, it can be seen that the Subscriber class requires an instance of the Publisher class that is raising the event. That is, the += operator is used to attach the TextingOnWithDrawal event handler to the onWithdrawal event raised by the publisher BankAccount. This can result in a number of problems. Construction of various class instances are typically spread across an entire code base. In fact, they can even reside in code bases outside the influence of the subscriber (such as in a dependent assembly). Therefore, the changes required to connect dynamic events are at best intrusive, and at worst impossible.
Attributes are also widely used in current computing languages. Attributes provide a method to associate metadata or declarative information with code (such as a program entity like a type, a method, a property or an assembly). In essence, attributes add metadata to a program entity. After an attribute is associated with a program entity, the attribute can be queried at runtime using a process known as reflection.
Metadata is information about the program entities defined in a program. In various languages, one or more attributes can be applied to entire assemblies, modules, or smaller program entities like classes and properties. Attributes can normally accept arguments just like methods and properties.
By way of specific example, in the computing language C#, attributes can be specified. They are specified by placing the attribute name in square brackets above the declaration of the entity that the attribute applies to. The target of an attribute is the entity to which it applies.
The discussion above is merely provided for general background information and is not intended to be used as an aid in determining the scope of the claimed subject matter.